package com.citydo.webrtcspringboot.websocket.stream;

import javax.websocket.Session;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class WebsocketService {
    public List<Session> sessionList = new ArrayList<>();
    public static final WebsocketService Instance = new WebsocketService();
    public void AddSession(Session session){
        sessionList.add(session);
    }
    public void RemoveSession(Session session){
        sessionList.remove(session);
    }
    public void SendMsg(String msg) throws IOException {
        for (Session session:
             sessionList) {
            if ((session == null)||!session.isOpen()||(msg == null)) {
                continue;
            }
            session.getBasicRemote().sendText(msg);
        }
    }
}
